<?php
class LayoutHelper extends AppHelper 
{
	var $helpers = array('Html', 'Javascript', 'Form','Ajax','Session','For','Json','Vista','Interfaz');
	//var $Html = null;
	//var $Javascript = null;
//	var $Ajax = null;



  public function menu($menu,$aux='menu')
  {
  ?>
    <br/ >
    <table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="center">
      <table border="1" cellpadding="0" cellspacing="0" width="97%">
      <?php
      $cont=''; 
      for($i=0; $i<count($menu); $i++)
      { 
  	    $iv='menuadmin'.$i.mktime(date("his")).$aux;
		    if($i==0) $clasenm='lis_selecmenuactivo'; 
		    else $clasenm='lis_selecmenu';
      ?>
		    <tr height="20px" bgcolor="#FFFFFF" class="<?php echo $clasenm;?>" style='cursor:pointer;'>
		    <?php 
        $controler=str_replace('/','xreplacex',$menu[$i]['url']);
        if(isset($menu[$i]['permiso']) && $menu[$i]['permiso']==1)
        {
          ?>
          <td align="left" id="<?php echo $iv;?>" onclick="cssmenu(this.id,'camposmenus_<?php echo $aux?>','<?php echo $menu[$i]['modelo'];?>','<?php echo $controler;?>');
          <?php  echo $this->Interfaz->ajax($menu[$i]['url'].'/'.$iv,$menu[$i]['div']);?>">
            &nbsp;<?php echo $this->Interfaz->font($menu[$i]['title'],'#545454');?>
          </td>
          <?php 
        }
        else
        {
          ?>
        <td align="left" id="<?=$iv?>" onclick="cssmenu(this.id,'camposmenus_<?php echo $aux?>','<?=$menu[$i]['modelo']?>','<?=$controler?>');
        <?php echo 'sin_permiso();';//$this->Interfaz->ajax(PRINCIPAL."/permiso/".$menu[$i]['div'],$menu[$i]['div']);?>">
        &nbsp;<?=$this->Interfaz->font($menu[$i]['title'],'#545454');?>
      </td>
            <? 
        }
    ?>
    </tr>
    <?
		$cont.=$iv.',';
}
?> 


<?

$cont=substr("$cont", 0, -1); 
?>
<input id="camposmenus_<?php echo $aux?>" type="hidden" value="<?=$cont?>"/>
</table></td></tr>
</table>



<?


  }



  public function plantilla($atributos=array(),$menu=array(),$areas=array(),$tipo_usuario=null,$right=array()) {

if(!isset($atributos['imagen']))$atributos['imagen']='agropatriamini.png';

$usua=$this->Interfaz->mayus($this->Session->read('username'));
$nombre_usuario=$this->Interfaz->mayus($this->Session->read('nombre_usuario'));
?>
<?=$this->Vista->loading('cargando');?>
<?=$this->Vista->loading('guardando');?>

<div id="headdiv" style=" border: 0px #000006 solid; border-width: 0px; border-color: 660033; height: 25px; width: 100%;">
<div id="titulohead" style="display:none;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="10px">
<tr>
<td width="4px" align="center"></td>
<td width="195px" align="left">
	<div id="leftCallout">
	<?=$this->Html->image($atributos['imagen'], array('border'=>'0', 'width'=>'64px', 'height'=>'24px', 'align'=>'absmiddle'));?>
	</div>
</td>
<td align="center">






<font color="red"><b id='msjsessioncerrada'> <!--"MENSAJE"--></b></font></td>
<?=$this->Vista->tipsayuda("ayudausuarioss","Usuario: ".$nombre_usuario,'info',250);?>
<td width="275px" align="right" valign="bottom"><font id="ayudausuarioss" class="colorcakephpsd" size="-1"><b>Usuario:</b> <?=$usua;?></font>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width="25px" align="center" id="tdayuda">
<?=$this->Vista->tipsayuda("helpayudas","Documentacion del Sistema",'info',150);?>
<? if(ayuda===0) {?>
<div align="helpayudas" class="helpayudas" width="25px" onclick="<?=$this->Interfaz->ajax(PRINCIPAL.'/documentacion',DOCULTO);?>">&nbsp;&nbsp;</div>
<? } else { ?>
<div align="helpayudas" class="helpayudas" width="25px" onclick="<?=$this->Interfaz->ajax(PRINCIPAL.'/ayuda',DOCULTO);?>">&nbsp;&nbsp;</div>
<? } ?>
</td>
<td width="25px" align="center" id="tdcerrarsession">
<?=$this->Vista->tipsayuda("cerrarsesions","Cerrar Session de $nombre_usuario",'info',300);?>
<?//echo $img_salir;?><a href="<?=$servidor=servidor;?>" style="cursor:pointer;"><div id="cerrarsesions" class="cerrarsesions">&nbsp;&nbsp;</div></a></td>
<td width="10px" align="center"></td>
</tr>
</table>
</div>
</div>



<?




if(isset($atributos['buscador']) and $atributos['buscador']==true)$buscadr=true;
else $buscadr=false;

$atributos['buscador']=true;
if(!isset($atributos['sistema']))$atributos['sistema']=sistema;

if(!isset($atributos['nombre_left']))$atributos['nombre_left']=" ";else $atributos['nombre_left']="title: '".$atributos['nombre_left']."',";
if(!isset($atributos['nombre_right']))$atributos['nombre_right']="";else $atributos['nombre_right']="title: '".$atributos['nombre_right']."',";

if(!isset($atributos['icono_left']))$atributos['icono_left']=" ";else $atributos['icono_left']="iconCls: '".$atributos['icono_left']."',";
if(!isset($atributos['icono_right']))$atributos['icono_right']=" ";else $atributos['icono_right']="iconCls: '".$atributos['icono_right']."',";

echo $this->Vista->sistema('Sistema '.$atributos['sistema'].' '.version.' ',null);


$hader="<script type='text/javascript'>

  Ext.require(['*']);
	Ext.Loader.setConfig({enabled: true});
	Ext.Loader.setPath('Ext.ux', 'js/tabs/');
  Ext.onReady(function() {

        Ext.QuickTips.init();
        Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));

        var viewport = Ext.create('Ext.Viewport', {
            id: 'border-example',
            layout: 'border',
            items: [
            // create instance immediately
/*xtype: 'box', // lazily created panel (xtype:'panel' is default)
id: 'configuracion', // see Ext.getCmp() below
*/
            Ext.create('Ext.Component', 
		      { 
			id: 'head', region: 'north',height: 0, minSize: 1800,maxSize: 200, 
		        autoEl: { tag: 'div',contentEl: 'headdiv'/*, html:' <h2> SISTEMA DE TARJETA PRODUCTIVA V 1.0</h2>'*/}
           	      }),
		      {

			id: 'piepagina', region: 'south', contentEl: 'pie_de_pagina', split: false,
               		height: 51, minSize: 0, maxSize: 100, collapsible: false, collapsed: false, iconCls: 'gogle_palena',
			title: 'SISTEMA - ".$this->Interfaz->mayus($atributos['sistema'])." ".version."', margins: '0 0 0 0'
          	      },  



		      {
			id: 'tabpanelss', region: 'east',xtype: 'tabpanel', ".$atributos['nombre_right']." ".$atributos['icono_right']."
		  	animCollapse: true, collapsible: true, collapsed: false, split: true,
		        width: 230, minWidth: 230, maxWidth: 400,  margins: '0 5 0 0',
		        activeTab: 0, tabPosition: 'bottom',";


if(count($right)>0 and isset($right[0]['div'])){
$hader.="
		        items: [{
		                  contentEl: '".$right[0]['div']."',	 autoScroll: true,";

if(isset($right[0]['title']))$hader.="title: '<span id=\'title_right\'>".$right[0]['title']."</span>',";
if(isset($right[0]['icono']))$hader.=" iconCls: 'application_view_list', ";

$hader.="		       		}],";
}


if($buscadr){
$hader.="
			dockedItems: [{
                   			dock: 'top', width: '100%', tooltip: 'buscador_todo', contentEl: 'buscador_todo'
              			     }],";

}


$hader.="


           	       },



		       {
               		 id: 'west-panel', region: 'west',xtype: 'panel', ".$atributos['nombre_left']." ".$atributos['icono_right']." stateId: 'navigation-panel',
		         animCollapse: true, collapsible: true, collapsed: false, split: true,
			 width: 200, minWidth: 200, maxWidth: 400, margins: '0 0 0 5',
		         layout: 'accordion',
		         items: [";


/*
if($tipo_usuario==1)
{

}
*/

for($i=0; $i<count($menu);$i++){
if(!isset($menu[$i]['title']))$title="title: '',";else $title="title: '".$menu[$i]['title']."',";
if(!isset($menu[$i]['div']))$div="contentEl: '".DLOAD."',";else $div="contentEl: '".$menu[$i]['div']."',";
if(!isset($menu[$i]['icono']))$icono="";else $icono="iconCls: '".$menu[$i]['icono']."',";
if(isset($menu[$i]['scroll']) and $menu[$i]['scroll']==true)$scroll="autoScroll: 'true'";else $scroll="autoScroll: 'false'";

$hader.="{ ".$title." ".$div." ".$icono." ".$scroll." },";
//echo '<br />'.$menu[$i]['div'] .', '.$menu[$i]['icono'];

}




$hader.="  { title: 'Informaci&oacute;n', contentEl: 'informacion_sistema', iconCls: 'information', autoScroll: false }
         

          ]
           	        },

						Ext.create('Ext.Panel', {
            //Ext.create('Ext.tab.Panel', {
                region: 'center',
								border:0,
                deferredRender: false,
             //   activeTab: 0,     // first tab initially active

/*

								dockedItems: [{
						   	dock: 'top', width: '100%', /*tooltip: 'botoneraunica', contentEl: 'botoneraunica', * /


						 									buttons: [{
												       contentEl: 'ssssssswwewewe',
																dock: 'top',
												          }]

	}],

*/

								dockedItems: [{
						 	dock: 'top', width: '100%', tooltip: 'botoneraunica', contentEl: 'botoneraunica',

/*
              //  xtype: 'toolbar',
						//		align: 'center',
								//width:700,
						//		border:1,
                items: [{
                    iconCls: 'application_go',
                    text: '<span id=\'title_".DLOAD."\'>".sistema."</span>',
										disabled: true,
                  //  scope: this,
                  //  handler: this.onAddClick
                }, {
                    iconCls: 'application_go',
                    text: 'Nuevo',
										disabled: false,
                  //  scope: this,
                  //  handler: this.onAddClick
                },{
                    iconCls: 'book',
                    text: 'Borrar',
                    disabled: false,
                    itemId: 'delete',
                  //  scope: this,
                 //   handler: this.onDeleteClick
                }]
   */ 

    			}],


                items: [{
                    contentEl: '".DLOAD."',
          //          title: '<span id=\'title_".DLOAD."\'>".sistema."</span>',
		    //iconCls: 'application_go',
                    closable: false,
                    autoScroll: true,
    //   width: '100%',
       height: '100%',
		   tooltip: 'Posicionamiento sobre el sistema'
                }/*, {
                    contentEl: '".DLOAD."',
                    title: 'Documentaci&oacute;n',
					iconCls: 'docum',
					autoScroll: true
                }, {
                    contentEl: '".DLOAD."',
                    title: 'Simulador de Manejo',
					iconCls: 'simulador',
					autoScroll: false
                }*/]
            })]
        });
       

    });



</script>";

//////////////////////////////// TABS 1 ///////////////////////////////////
$mktime=mktime(date('his'));
$hader.="<div id='".DLOAD."' class='x-hide-display'>

<table border='0' cellpadding='0' cellspacing='0' width='100%' height='100%'>
<tr><td align='center'>
<br /><br /><br /><br />
<img id='logoagropatriaxxxx$mktime' src='/img/agropatria.png' style='filter: alpha(opacity=50); opacity: .2' border='0' align='absmiddle'>";

//$hader.=$this->Vista->lisamplia("logoagropatriaxxxx$mktime");

$hader.="</td>
</tr>
</table>

</div>";

$hader.="<div id='cakeidadmin' class='x-hide-display'></div>";

//////////////////////////////// TABS 123 ///////////////////////////////////
$hader.="<div id='".DOCULTO."' class='x-hide-display'></div>";


 ////////////////////////// informacion del sistema /////////////////////////
$hader.="<div id='informacion_sistema' class='x-hide-display' align='center'>";



if($_SERVER['REMOTE_ADDR']=='127.0.0.1')
$ip = '<b>Servidor</b>';
else if($_SERVER['REMOTE_ADDR']=='1')
$ip = '<b>Servidor</b>';
else
$ip = ''.$_SERVER['REMOTE_ADDR'];

//$oncliks=$this->Interfaz->ajax(PRINCIPAL.'/informacion','informacion_sistema');
$oncliks='';
$hader.="
<table border='0' cellpadding='0' cellspacing='0' width='200px' align='left' style='border:1;'>
<tr>
<td height='2px'>
</td>
</tr>
<tr>
<td colspan='2'  onclick=\"$oncliks\">
<table border='1' cellpadding='0' cellspacing='0' width='99%' align='left' style='border:1;'>";

$this->Vista->tipsayuda('resulxxx','Resolucion del monitor: ANCHO x  LARGO','info','220');

$hader.="
<tr align='center' style='cursor:pointer;' id='resulxxx' class='lis_selec'>
<td width='95px' align='left'><font color='#545454' size='-1' align='left'>&nbsp;<b>Resolucion:</b>&nbsp;</font></td>
<td  align='center'><font color='#545454' size='-1' align='left' id='resolucions'>&nbsp;&nbsp;</font></td>";
$hader.="<script type='text/javascript'>document.getElementById('resolucions').innerHTML=screen.width + ' x ' + screen.height;</script>";

$hader.="</tr>";

$userAgent = $_SERVER['HTTP_USER_AGENT'];
$userAgent = strtolower ($userAgent);
if(strpos($userAgent, "windows") !== false)
{
	$sopet="Windows";
  $imgsop=$this->Html->image('iconos/icons/windows.png', array('border'=>'0', 'width'=>'16px', 'height'=>'16px', 'align'=>'absmiddle'));
  $imgsxx=$this->Html->image('iconos/icons/windows.png', array('border'=>'0', 'width'=>'64px', 'height'=>'64px', 'align'=>'absmiddle'));
}
else if(strpos($userAgent, "linux") !== false)
{
	$sopet="Linux";
  $imgsop=$this->Html->image('iconos/icons/linux.png', array('border'=>'0', 'width'=>'16px', 'height'=>'16px', 'align'=>'absmiddle'));
  $imgsxx=$this->Html->image('iconos/icons/linux.png', array('border'=>'0', 'width'=>'64px', 'height'=>'64px', 'align'=>'absmiddle'));
}
else
{
    $sopet="Otros";
    $imgsop=$this->Html->image('iconos/icons/linux.png', array('border'=>'0', 'width'=>'16px', 'height'=>'16px', 'align'=>'absmiddle'));
    $imgsxx=$this->Html->image('iconos/icons/linux.png', array('border'=>'0', 'width'=>'64px', 'height'=>'64px', 'align'=>'absmiddle'));
}




$this->Vista->tipsayuda('sistexxx',''.$sopet.'<br /> '.$imgsxx,'info','100');
$hader.="
<tr align='center' style='cursor:pointer;' id='sistexxx' class='lis_selec'>
<td width='95px' align='left'><font color='#545454' size='-1' align='left'>&nbsp;<b>Plataforma:</b>&nbsp;</font></td>
<td  align='left'><font color='#545454' size='-1' align='left'>
$imgsop
$sopet&nbsp;</font></td>
</tr>";
$this->Vista->tipsayuda('direcxxx','Direccion IP de esta maquina: '.$ip,'info','250');

$hader.="
<tr align='center' style='cursor:pointer;' id='direcxxx' class='lis_selec'>
<td align='left'><font color='#545454' size='-1' align='left'>&nbsp;<b>Direccion IP:</b>&nbsp;</font></td>
<td align='left'><font color='#545454' size='-1' align='left'>&nbsp;$ip&nbsp;</font></td>
</tr>";
$this->Vista->tipsayuda('horaxxxx','Hora Acceso: '.$this->Session->read('hora_acceso'),'info','180');
$hader.="
<tr align='center' style='cursor:pointer;' id='horaxxxx' class='lis_selec'>
<td align='left'><font color='#545454' size='-1' align='left'>&nbsp;<b>Hora Acceso:</b>&nbsp;</font></td>

<td align='left'><font color='#545454' size='-1' align='left'>&nbsp;".$this->Session->read('hora_acceso')."";
//$this->Interfaz->font($this->Session->read('hora_acceso'),'#FFFFFF','18px');
$hader.="
&nbsp;</font></td>
</tr>";
$this->Vista->tipsayuda('fechaxxx','Fecha actual del sistema: '.date('d-m-Y'),'info','220');
$hader.="
<tr align='center' style='cursor:pointer;' id='fechaxxx' class='lis_selec'>
<td align='left'><font color='#545454' size='-1' align='left'>&nbsp;<b>Fecha actual:</b>&nbsp;</font></td>
<td align='left'><font color='#545454' size='-1' align='left'>&nbsp;<font color='#545454' size='-1' align='left'>".date('d-m-Y')."</font>";
$hader.="&nbsp;</font></td>
</tr>
</table>
</td>
</tr>
</table>
";



$hader.="
</div>";



/////////////////////////////// PIE DE PAGINA ///////////////////////////// 

$hader.="<div id='pie_de_pagina' class='x-hide-display'></div>";	

$hader.="<div id='".DVENTANA."'></div>";

$hader.="<div id='prueba' class='x-hide-display'></div>";

$hader.="<div id='ayudadivtodo' style='width:100%;' class='x-hide-display'>
<div id='ayudadiv' style='width:100%; height: 70%; background-color:#FFFFFF;'></div>
<div id='ayudabottomdiv' style='overflow-x: auto; overflow-y: auto; width:100%; height: 30%; background-color:#FFFFFF;'></div>
</div>
";

if($buscadr){
$hader.="
<div id='buscador_todo' align='center' class='x-hide-display botoneraunicacakea'>
<table border='0' cellpadding='10' cellspacing='10' width='90%' height='100%' align='center'>
	<tr>		<td align='center'>";
$hader.=$this->Form->input('dondepermiso',array('id'=>'dondepermiso','value'=>'', 'readonly'=>'false', 'label'=>false,'type'=>'hidden', 'div'=>false,'error'=>false));
$hader.=$this->Form->input('dondemodelo',array('id'=>'dondemodelo','value'=>'vacio', 'readonly'=>'false', 'label'=>false,'type'=>'hidden', 'div'=>false,'error'=>false));
$hader.=$this->Form->input('dondecontroler',array('id'=>'dondecontroler','value'=>'vacio', 'readonly'=>'false', 'label'=>false,'type'=>'hidden', 'div'=>false,'error'=>false));
$hader.=$this->Vista->tipsayuda('buscadorindex','<span id="titlebuscador"> Escriba y presione ENTER <br />y se filtrara por lo escrito<br /></span>','buscador',200);
$hader.=$this->Form->input('buscadorindex',array('id'=>'buscadorindex','value'=>'', 'readonly'=>'false', 'label'=>false,'type'=>'text', 'div'=>false,'error'=>false, 'class'=>'buscar2', 'maxlength'=>'20','onkeyup'=>$this->Interfaz->ajaxbuscador(PRINCIPAL.'/buscador',DLOAD,array('dondemodelo','dondecontroler','buscadorindex','dondepermiso'))));

$hader.="	</td>	</tr></table></div>";

}





$hader.="
<script type='text/javascript'>
if(document.getElementById('titulohead')!=null)
document.getElementById('titulohead').style.display='block';
</script>";

echo $hader;

?>




<div id="botoneraunica" align="center" class="x-hide-display botoneraunicacakea">
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="25px" align="center">
	<tr>
		<td align="right" width="5px">
&nbsp;<?$dloa=DLOAD;?>
		</td>
		<td align="left" id="title_<?=$dloa;?>" valign='button'><font class="fondocakeosdsssistema"><b><?=sistema?></b></font>

		</td>

<?  
$mktime=mktime(date('his'));
$carg=$mktime;

$atrib='cursor:pointer; border: 0;height:16px; color:gray;top:0;';
$atribhover='cursor:pointer; border: 0;height:18px; color:red;top:0;';
//$class='x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon x-btn-center';
$class='x-toolbar-item x-btn-default-small x-focus x-btn-focus x-btn-default-small-focus x-over x-btn-over x-btn-default-small-over over';
$ruta='../../img/iconos/icons/botonesmicro/';


echo '
<style type="text/css">
#buttonnuevolayoutinput{'.$atrib.'background: url(\''.$ruta.'1364925873_document-new.png\') no-repeat;}
#buttonnuevolayoutinput:hover{'.$atribhover.';background: url(\''.$ruta.'1364925869_tests.png\') no-repeat;}

#buttonfiltrolayoutinput{'.$atrib.';background: url(\''.$ruta.'1364926098_old-edit-find.png\') no-repeat;}
#buttonfiltrolayoutinput:hover{'.$atribhover.'background: url(\''.$ruta.'1364926098_old-edit-find.png\') no-repeat;}

#buttonpdflayoutinput{'.$atrib.'background: url(\''.$ruta.'1364925864_pdf.png\') no-repeat;}
#buttonpdflayoutinput:hover{'.$atribhover.'background: url(\''.$ruta.'1364925860_ACP_PDF 2_file_document.png\') no-repeat;}

#buttonexellayoutinput{'.$atrib.'background: url(\''.$ruta.'1364925880_application-vnd.ms-excel.png\') no-repeat;}
#buttonexellayoutinput:hover{'.$atribhover.'background: url(\''.$ruta.'1364925880_application-vnd.ms-excel.png\') no-repeat;}

#buttoncallayoutinput{'.$atrib.'background: url(\''.$ruta.'1364925877_application-vnd.ms-word.png\') no-repeat;}
#buttoncallayoutinput:hover{'.$atribhover.'background: url(\''.$ruta.'1364925877_application-vnd.ms-word.png\') no-repeat;
</style>

';


?>

		<td align="right" width="1px" id='buttonnuevolayout'><? echo "<input id=\"buttonnuevolayoutinput\" type=\"hidden\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;Nuevo\" disabled/>";?></td>
		<td align="right" width="1px" id='buttonfiltrolayout'><? echo "<input id=\"buttonfiltrolayoutinput\" type=\"hidden\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;Filtro\"disabled />";?></td>
		<td align="right" width="1px" id='buttonpdflayout'><? echo "<input id=\"buttonpdflayoutinput\" type=\"hidden\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;Pdf\" disabled>";?></td>
		<td align="right" width="1px" id='buttonexellayout'><? echo "<input id=\"buttonexellayoutinput\" type=\"hidden\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;Exel\" disabled>";?></td>
		<td align="right" width="1px" id='buttoncallayout'><? echo "<input id=\"buttoncallayoutinput\" type=\"hidden\" value=\"&nbsp;&nbsp;&nbsp;&nbsp;Cal\" disabled>";?></td>
		<td align="right" width="1px" id='buttonpruebalayout'><!--Prueba--></td>
	</tr>
</table>
</div>





<?


  }

}
?>
